package 全国粗离婚率;

import org.apache.hadoop.io.Writable;
import java.io.DataInput;
import java.io.DataOutput;
import java.io.IOException;

public class DivorceRateBean implements Writable {

    private float divorceCount;//离婚登记数
    private long populationCount;//总人口
    private double divorceRate;

    public DivorceRateBean() {
    }

    // 全参构造函数，方便初始化对象并赋值
    public DivorceRateBean( float divorceCount, long populationCount,double divorceRate) {
        this.divorceCount = divorceCount;
        this.populationCount = populationCount;
        this.divorceRate = divorceRate;
    }

    public void set(float divorceCount, long populationCount) {

        this.divorceCount = divorceCount;
        this.populationCount = populationCount;
    }

    public void set(double divorceRate) {
        this.divorceRate = divorceRate;
    }


    // Getter和Setter方法
    public float getDivorceCount() {
        return divorceCount;
    }

    public void setDivorceCount(float divorceCount) {
        this.divorceCount = divorceCount;
    }

    public long getPopulationCount() {
        return populationCount;
    }

    public void setPopulationCount(long populationCount) {
        this.populationCount = populationCount;
    }

    public double getDivorceRate(){return divorceRate;}

    public void setDivorceRate(double divorceRate) { this.divorceRate = divorceRate; }

    @Override
    public String toString() {
        return "粗离婚率：" + divorceRate + "%";
    }

    // 重写write方法，将对象数据序列化输出
    @Override
    public void write(DataOutput out) throws IOException {
        out.writeFloat(divorceCount);
        out.writeLong(populationCount);
        out.writeDouble(divorceRate);
    }

    // 重写readFields方法，从输入流反序列化数据填充对象属性
    @Override
    public void readFields(DataInput in) throws IOException {
        divorceCount = in.readFloat();
        populationCount = in.readLong();
        divorceRate = in.readDouble();
    }

}